package org.mogu.control;


import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.impl.client.DefaultHttpClient;
import org.mogu.R;
import org.mogu.Welcome;
import org.mogu.service.GetSyncUrl;
import org.mogu.staticvalue.Convert;
import org.mogu.tools.UrlSync;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Replay21 extends RelativeLayout {
	TextView weibocontent;
//	EditText edittext;
	Button cancelbtn;
	Button replaybtn;
	Button sendbtn;
	Replay21 replay21;
	String code;
	String replayType;
	String maincode;
	String father;
	Welcome welcome;
	
	
	ArrayList<String> appMap;

	DefaultHttpClient client;
	HttpResponse httpResponse;

	public Replay21(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public Replay21(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.replay21, this, true);
		weibocontent = (TextView) findViewById(R.id.replay21content);
		cancelbtn = (Button) findViewById(R.id.replay21_cancel);
		cancelbtn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				welcome.goBack();
			}
		});
		sendbtn = (Button) findViewById(R.id.replay21_resend);
		sendbtn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				String url;
				String urlparam;
				url = GetSyncUrl.getAppUrlByCode(maincode) + "/sendgroup";
				urlparam="&Code="+code+"&MainCode="+maincode+"&Type="+replayType+"&Content=1";
				UrlSync urlSync=new UrlSync();
				urlSync.setNotice(false);
				urlSync.setUri(url);
				urlSync.setUrlparam(urlparam);
				urlSync.setMaincode(maincode);
				urlSync.setCode(code);
				urlSync.setResultType(replayType);
				urlSync.setToastContentFa("订阅失败。");
				urlSync.setToastContentSu("订阅成功。");
				synchronized (Convert.class) {
					Convert.syncList.add(0,urlSync);
				}
//				new Thread() {
//					public void run() {
//				try {
//					client = new DefaultHttpClient();
//					String url;
//					url = GetSyncUrl.getAppUrlByCode(maincode) +  "/sendgroup"
//							+ Convert.uname + "&UserPwd=" + Convert.upwd+"&Code="+code+"&MainCode="+maincode+"&Type="+replayType+"&Content=1";
//					HttpGet getMethod = new HttpGet(url+ Convert.testNum);
//
//					httpResponse = client.execute(getMethod);
//////					welcome.myDialog = new ProgressDialog(welcome);
//////					ProgressDialog.show  
//////					    	(
//////					    			welcome,
//////						    		"正在同步",
//////						    		"正在下载数据，请稍候......"
//////						    	);
////					welcome.myDialog.setCancelable(false);
////					welcome.myDialog.setMessage("正在下载数据，请稍候......");
////					welcome.myDialog.setButton("后台运行",new DialogInterface.OnClickListener() {
////
////						@Override
////						public void onClick(DialogInterface dialog, int which) {
////							// TODO Auto-generated method stub
////							dialog.cancel();
////							
////						}
////					});
////					welcome.initDialog(null, null);
////					welcome.myDialog.show();
////					welcome.myDialog.setOnDismissListener(new OnDismissListener() {
////						
////						public void onDismiss(DialogInterface dialog) {
////							// TODO Auto-generated method stub
////							welcome.refash();
////						}
////					});
//					if (httpResponse.getStatusLine().getStatusCode() == 200) {
//						// 取出回应字串
//						String strResult;
//						strResult = EntityUtils.toString(httpResponse
//								.getEntity());
//						if ("1".equals(strResult)) {
////							Toast.makeText(welcome, "订阅失败，稍后再试。", 4000).show();
//						}else{
////							Toast.makeText(welcome, "订阅成功，系统正在后台更新数据。", 4000).show();
//							ImgLibSync infoSync=new ImgLibSync();
//							infoSync.syncw(welcome, DBhelper.getDBHelper(welcome), strResult.split(";"));
//							
//						}
//					}else{
////						Toast.makeText(welcome, "订阅失败，稍后再试。", 4000).show();
//					}
//				} catch (Exception e1) {
////					e1.printStackTrace();
////					welcome.myDialog.dismiss();
//				}finally{
////					welcome.goBack();
//					
//				}
//					}}.start();
					welcome.goBack();
					Toast.makeText(welcome, "正在提交", 4000).show();
				
			}
		});
		
		
	}

	public void setContent(String code,String father, String replayType, String maincode,
			 String content) {
//		weibocontent.setText(content);
		this.code = code;
		this.replayType = replayType;
		this.maincode = maincode;
		this.father=father;
		weibocontent.setText(content);
		
		
	}
	
	

	public void setReplay(Replay21 content, Welcome welcome) {
		replay21 = content;
		this.welcome = welcome;
//		appMap=AppUrlMap.getAppUrlByCode(Convert.uname, this.maincode, DBhelper.getDBHelper(this.welcome).getReadableDatabase());
	}

}
